"""
-*- coding:utf-8 -*-
最终版web自动化
Author: HaoWei
DataTime: 2021/11/12 11:05
TODO 开始运行的执行通道
在此运行所有用例

"""
import unittest
import time
import HTMLTestRunnerCN
from public_tools.emalTool import EmailTool

if __name__ == '__main__':
    t = EmailTool()
    report_dir = './test_report'
    test_dir = './testcase'

    discover = unittest.defaultTestLoader.discover(test_dir, pattern='Tester*.py')  # TODO 填写需要测试的类名
    suite = unittest.TestSuite()
    now = time.strftime('%Y-%m-%d %H_%M_%S')
    report_name = report_dir + '/' + now + '测试报告.html'

    suite.addTest(discover)
    f = open(report_name, 'wb')  # wb 二进制文件的写操作

    runner = HTMLTestRunnerCN.HTMLTestRunner(stream=f, title='商机自动化测试报告', description='whw')
    # f.close()
    runner.run(suite)
    f = open(report_name, 'rb')
    report_con = f.read()
    t.doMail_text('UI自动化测试', report_con.decode())
